<template>
  <el-dialog :visible.sync="visible" width="70%" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form v-loading="loading" :model="dataForm"  ref="dataForm" :label-width="$i18n.locale === 'en-US' ? '120px' : '120px'">
      <el-col :span="8">
        <!-- 应用ID -->
        <el-form-item label="应用ID" prop="appId">
          <el-input v-model="dataForm.appId" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <!-- 接口api method -->
        <el-form-item label="接口编码" prop="apiCode">
          <el-input v-model="dataForm.apiCode" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <!-- 接口请求时间 -->
        <el-form-item label="报文ID">
          <el-input v-model="dataForm.id" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <!-- 接口请求时间 -->
        <el-form-item label="接口请求时间" prop="timestamp">
          <el-input v-model="dataForm.timestamp" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <!-- 接口请求签名  唯一索引 -->
        <el-form-item label="接口请求签名" prop="sign">
          <el-input v-model="dataForm.sign" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <!-- 接口请求URL参数 -->
        <el-form-item label="接口请求参数" prop="requestParams">
          <el-input v-model="dataForm.requestParams" type="textarea" :rows="2" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <!-- 接口请求body参数体 -->
        <el-form-item label="接口请求参数体" prop="requestBody">
          <el-input v-model="dataForm.requestBody" type="textarea" :rows="3" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <!-- 报文处理状态 0-未处理 1-处理中 2-处理成功 3-处理失败 -->
        <el-form-item label="报文处理状态" prop="dealFlag">
          <el-select v-model="dataForm.dealFlag" disabled>
            <el-option v-for="template in $getDictList('API_DEAL_FLAG', true)"
                       :key="$xeutils.toInteger(template.val)"
                       :label="template.label"
                       :value="$xeutils.toInteger(template.val)"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <!-- 处理时间 -->
        <el-form-item label="处理时间" prop="dealTime">
          <el-input v-model="dataForm.dealTime" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <!-- 处理失败次数 -->
        <el-form-item label="处理失败次数" prop="dealRetry">
          <el-input v-model="dataForm.dealRetry" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <!-- 详细看处理日志 -->
        <el-form-item label="处理描述" prop="dealDesc">
          <el-input v-model="dataForm.dealDesc" type="textarea" :rows="2" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
    </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('close') }}</el-button>
    </template>
  </el-dialog>
</template>
<script>
export default {
  data () {
    return {
      loading: false,
      visible: false,
      dataForm: {
        id: '',
        appId: '',
        method: '',
        timestamp: '',
        sign: '',
        requestParams: '',
        requestBody: '',
        responseStr: '',
        dealFlag: '',
        dealDesc: '',
        dealTime: '',
        dealRetry: '',
        creator: '',
        createDate: ''
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.loading = true
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/api/apiReceiptInfo/${this.dataForm.id}`).then(({ data: res }) => {
        this.loading = false
        if (res.code !== 0) {
          return false
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    }
  }
}
</script>
